package com.hmall.gateway.filter;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class MyGlobalFilter implements GlobalFilter , Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        System.out.println("执行了MyGlobalFilter过滤器pre...");
        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
            System.out.println("执行了MyGlobalFilter过滤器post...");
        }));
    }

    @Override
    public int getOrder() {
        // 设置MyGlobalFilter的执行顺序，值越小，优先级越高
        return 0;
    }
}
